<template>
  <view class="home">
    <view class="homeBack">
      <view class="homeBox" :class="{hei117:recruitInfoLength===0}">
        <view class="homeTop">首页</view>
        <view class="padd16">
          <u-search
            placeholder="请输入职位名称"
            animation="false"
            v-model="positionName"
            :show-action="false"
          ></u-search>
        </view>
        <!-- 分享按钮 -->
        <view class="fenxiangBox" @click="openFenxiang">
          <view>
            <img class="fenxiang" src="../../static/fenxiang.png" alt />
            <view class="fenxiangTest">分享</view>
          </view>
        </view>
      </view>
      <view class="contentHoCon">
        <view class="loadingShow">
          <u-loading :show="loadMore" size="48"></u-loading>
        </view>
        <view
          ref="homeUl"
          class="contentHoConBack"
          v-for="i in recruitInfoslistAll"
          :key="i"
          @click="openRecruitment(i)"
        >
          <view class="contentHoConBackTop">
            <view class="contentHoConBackTop1">
              <view class="whitNoWrap contentHoConBackTop1Wwidth">
                {{
                i.postName
                }}
              </view>
              <text v-if="i.isEmergency" class="contentHoConBackTop2">急招</text>
              <text class="contentHoConBackTop22" v-if="i.workType && i.workType === 1">全职</text>
              <text class="contentHoConBackTop33" v-if="i.workType && i.workType === 2">兼职</text>
            </view>
            <view class="contentHoConBackTop3">
              <span v-if="i.lowestSalary === i.highestSalary">{{ i.highestSalary }}元</span>
              <span v-else>{{ i.lowestSalary }}-{{ i.highestSalary }}元</span>
              <text>/{{ salaryGrantTypeArr[i.salaryGrantType] }}</text>
            </view>
          </view>
          <view class="paddtop10 contentHoConBackName">
            <view class="contentHoConBackTime">
              <text>{{i.workingSeniority | workingSeniorityFun}}</text>
              <text class="magRight8">|</text>
              <text class="magRight8">{{i.lowestEducation | lowestEducationFun}}</text>
            </view>
            <view class="alignItem" v-if="i.empRuleIsOpen">
              <img class="shang" src="../../static/shang.png" alt />
              <text class="shangNum">{{i.empMoneyReward||'0'}}</text>
            </view>
          </view>
          <view class="contentHoConBackName paddtop10">
            <view>
              <text>{{ i.companyUnitName }}</text>
            </view>
            <view>
              <text class="paddLeft fontColorAC">
                <text :key="z" v-for="z in i.cityName.split(',').splice(1)">
                  {{
                  z
                  }}
                </text>
              </text>
            </view>
          </view>
        </view>
        <view style="text-align: center;margin-top: 56px;" v-if="recruitInfoslistAll.length===0">
          <img style="width:200px;height:200px" src="../../../static/images/meiyou.png" alt />
          <view style="padding-top:15px">暂无记录</view>
        </view>
        <view style="height:80px"></view>
      </view>
    </view>
    <cTabBar />
  </view>
</template>

<script>
import { verify_home } from "@/utils/public";
import { recruitInfos } from "./api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      salaryGrantTypeArr: ["小时", "日", "月", "年"],
      userShow: false,
      regionShow: false,
      recruitIdsCacheKey: "",
      recruitIdsCacheShow: false,
      firstShow: false,
      loadMore: false,
      pageCount: 0,
      recruitInfoslistAll: [],
      recruitInfoLength: 0,
      pageNo: 1,
      isEmergency: true,
      descShow: false,
      positionName: "",
      list: [
        {
          name: "apple",
          checked: false,
          disabled: false
        },
        {
          name: "banner",
          checked: false,
          disabled: false
        }
      ]
    };
  },
  watch: {
    positionName() {
      this.pageNo = 1;
      this.recruitInfoslistAll = [];
      this.getListAllByIsCancel();
    }
  },
  computed: {
    ...mapState(["user", "jobSeeker"]),
    ...mapState(["site"]),
    siteId() {
      return this.user.siteId;
    }
  },
  created() {
    verify_home()
      .then(() => {})
      .catch(() => {
        uni.navigateTo({
          url: `/authorize/index`
        });
      });
    this.getListAllByIsCancel();
  },
  mounted() {},
  filters: {
    workingSeniorityFun(val) {
      if (val === 1) {
        return "不限";
      } else if (val === 2) {
        return "应届生";
      } else if (val === 3) {
        return "1-3年";
      } else if (val === 4) {
        return "3-5年";
      } else if (val === 5) {
        return "5-10年";
      } else if (val === 6) {
        return "10年以上";
      } else {
        return "";
      }
    },
    lowestEducationFun(val) {
      if (val === 1) {
        return "初中";
      } else if (val === 2) {
        return "中专";
      } else if (val === 3) {
        return "大专";
      } else if (val === 4) {
        return "高中";
      } else if (val === 5) {
        return "本科";
      } else if (val === 6) {
        return "硕士";
      } else if (val === 7) {
        return "博士";
      } else if (val === 8) {
        return "其他";
      } else {
        return "";
      }
    }
  },
  methods: {
    goRegion() {
      this.regionShow = true;
    },
    onReach() {
      // 显示加载图标
      this.pageNo++;
      if (this.pageCount < this.pageNo) {
        // 不加载
      } else {
        this.getListAllByIsCancel();
      }
    },
    chooseShowFun(e) {
      if (e === 1) {
        this.isEmergency = true;
        this.descShow = false;
      } else {
        this.isEmergency = false;
        this.descShow = true;
      }
      this.pageNo = 1;
      this.recruitInfoslistAll = [];
      this.getListAllByIsCancel();
    },
    getListAllByIsCancel() {
      console.log("user", this.user);
      const data = {
        "orders[0].desc": true,
        "orders[0].property": this.isEmergency ? "isEmergency" : "publicDate",
        isCancel: 2,
        isEmp: 1,
        positionName: this.positionName,
        pageSize: 10,
        hadNumber: true,
        pageNo: this.pageNo,
        siteId: this.$store.state.user.siteId,
        empCompanyId: this.site.companyId
      };
      this.loadMore = true;
      recruitInfos(data)
        .then(res => {
          this.loadMore = false;
          console.log(res);
          this.pageCount = res.pageCount;
          this.$emit("pageCountFun", this.pageCount);
          this.recruitInfoslistAll = [
            ...this.recruitInfoslistAll,
            ...res.entities
          ];
          this.recruitInfoLength = this.recruitInfoslistAll.length;
        })
        .catch(err => {
          console.log(err);
        });
    },
    openRecruitment(e) {
      console.log(e);
      uni.navigateTo({
        url: `/recruitment/recruitment/recruitmentDetails/recruitmentDetails?recruitInfoId=${e.id}`
      });
    },
    openFenxiang() {
      uni.navigateTo({
        url: `/share/share/shareDetails/shareDetails`
      });
    }
    //
  }
};
</script>

<style lang="scss">
@import "../../styles/styles.scss";
@import "./index.scss";
</style>
